package io.renren.softpark.controller;

import com.yunlong.common.utils.R;
import io.renren.softpark.dto.OnLineUserDto;
import io.renren.softpark.form.UserForm;
import io.renren.softpark.service.HomeService;
import org.apache.catalina.core.ApplicationContext;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: Cui
 * @Date: 2020/8/23
 * @Description:
 */
@RestController
@RequestMapping("generator/home")
public class HomeController {



    private ApplicationContext applicationContext;

    @Autowired
    HomeService homeService;

    @RequestMapping("/getWebOverview")
    public R getWebOverview(){
        return R.ok().put("data",homeService.getWebOverview());
    }

    @RequestMapping("/waitVerify")
    public R getNeedVerify(){
        return R.ok().put("data",homeService.getWaitVerify());
    }

    @RequestMapping("/getTendency")
    public R getTendency(){
        return R.ok().put("data",homeService.getTendency());
    }

    /**
     * 根据UserId查询出用户信息页面的
     * 用户详细信息
     * 发布过的栏目信息
     * 发布过的软件信息
     * @param userForm
     * @return
     */
    @RequestMapping("/getPersonalDetail")
    public R getPersonalDetail(@RequestBody UserForm userForm){
        return R.ok().put("data",homeService.getPersonalDetail(userForm.getUserId()));
    }

    @RequestMapping(value = "/getOnlinePeople")
    public R getOnlinePeople(){
        List<OnLineUserDto> onLineUser = homeService.getOnLineUser();
        R r = R.ok().put("OnLineUserDtoList",onLineUser);
        if ( onLineUser.size()==0) {
            return R.ok("当前无用户登录！");
        }else {
            return r;
        }
    }



}
